import {_decorator, Component, Node, find} from 'cc';
import {EventManager} from "db://assets/Scripts/Common/EventManager";
import {EventType} from "db://assets/Scripts/Common/EventType";

const {ccclass, property} = _decorator;

/**
 * 菜单管理器
 */
@ccclass('MenuManager')
export class MenuManager extends Component {

    onEnable() {
        // 注册菜单可见性事件
        EventManager.on(EventType.MENU_VISIBILITY, this.menuVisibility, this);
    }

    onDisable() {
        // 取消注册菜单可见性事件
        EventManager.off(EventType.MENU_VISIBILITY, this.menuVisibility, this);
    }

    start() {

    }

    update(deltaTime: number) {

    }

    /**
     * 设置菜单可见性
     *
     * @param menuPath 菜单节点路径
     * @param visibility true 可见，false 不可见
     */
    private menuVisibility(menuPath: string, visibility: boolean) {
        find(menuPath).active = visibility;
    }
}